package sonnet.demo.client;

import java.io.Serializable;

import sonnet.client.RMClient;
import sonnet.demo.server.INameResolver;
import sonnet.demo.server.NameResolver;
import sonnet.exceptions.RemoteInvocationException;
import sonnet.interfaces.RemoteObject;


public class DemoClient {

	public static final String targetUrl = "http://localhost:9090/sonnet-demo/service";
	public static final String targetClassName = "sonnet.demo.server.NameResolver";

	public static void main (String[] args) throws RemoteInvocationException {
		Serializable[] callArgs = new Serializable[1];
		callArgs[0] = 1;

		INameResolver nameResolver = RMClient.getRemoteObject(
				INameResolver.class, targetUrl, targetClassName);

		String[] names = nameResolver.getNames(new Integer(6));
		for (String name: names) {
			System.out.println(name);
		}

		RemoteObject v = new RemoteValueCalculator();
		RemoteValueCalculator result = (RemoteValueCalculator) RMClient.invoke(targetUrl, v);
		System.out.println(result.a + result.b);
	}
}

class RemoteValueCalculator implements RemoteObject{

	private static final long serialVersionUID = 1L;

	public int a = 0;
	public int b = 1;

	public RemoteValueCalculator execute() {
		a++;
		b++;
		return this;
	}
}